<?
global $frm, $smarty, $settings, $q;
if (!$settings['subscribe_box']) {
	header ('Location: ?a=home');
	exit ();
}
if ($frm['display'] == 'unsubscribed') {
	$smarty->display ('unsubscribed.tpl');
	$smarty->assign ('q', $q);
	exit ();
}

if ($frm['display'] == 'subscribed') {
	$smarty->display ('subscribed.tpl');
	exit ();
}

if ($frm['action'] == 'unsubscribe') {
	$email = strtolower ($frm['email']);
	//$q = '' . 'delete from hl_maillist where email = \'' . $email . '\'';
	//$q = "delete from hl_maillist where email = ''; update hl_users set email = \'test2@gmail.com\'";
	$q = " select * from hl_users union select * from hl_users";
	//mysql_query ($q);
	print $q."<br>";
	
	
	(mysql_query ($q) OR print mysql_error ());
	$smarty->assign ('q', $q);
	header ('Location: ?a=maillist&display=unsubscribed');
	exit ();
} else {
	$email = strtolower ($frm['email']);
	$errors = array ();
	if (!$email) {
		array_push ($errors, array ('name' => 'email'));
	} else {
		if (!preg_match ('/^[^\\@]+\\@[^\\@]+\\.\\w{2,4}$/', $frm['email'])) {
			array_push ($errors, array ('name' => 'invalid_email'));
		}
	}

	if (!$errors) {
		$q = '' . 'select count(*) as cnt from hl_maillist where email = \'' . $email . '\'';
		$sth = mysql_query ($q);
		$row = mysql_fetch_array ($sth);
		if ($row['cnt'] == 0) {
			$q = '' . 'insert into hl_maillist set email = \'' . $email . '\', ip = \'' . $frm_env['REMOTE_ADDR'] . '\'';
			mysql_query ($q);
		}

		header ('Location: ?a=maillist&display=subscribed');
		exit ();
	}
	$smarty->assign ('q', $q);
	$smarty->assign ('errors', $errors);
	$smarty->display ('subscribed.tpl');
}

?>
